<?php

namespace app\common\traits;

use think\db\Query;

trait ReModel
{
   public function __call($method, $args)
   {
       $query = parent::__call($method, $args);

       // 判断变量是否是 MyClass 的实例
       if ($query && !isset($this->query) && $query instanceof Query) {
           $this->query = $query;
       }

       return $query;
   }

   public static function __callStatic($method, $args)
   {
       $model = new static();

       $method2 = $method.'Data';
       if (method_exists($model, $method2)) {
           return call_user_func_array([$model, $method2], $args);
       }

       return parent::__callStatic($method, $args);
   }

   /**
    * 获取当前的查询参数
    * @access public
    * @param string $name 参数名
    * @return mixed
    */
   public function getOptions(string $name = '')
   {
       return isset($this->query) ? $this->query->getOptions($name) : '';
   }

}